package com.ycz.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ycz.entity.TUser;
import com.ycz.service.TUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ycz
 * @since 2021-09-25
 */
@Controller
@RequestMapping("/user")
public class TUserController {

    @Autowired
    private TUserService tUserService;

    @PostMapping("/login")
    public String login(String email, String password, HttpSession session){
        System.out.println(email+password);
        QueryWrapper<TUser> tUserWrapper=new QueryWrapper<>();
        tUserWrapper.lambda()
                .eq(TUser::getEmail,email)
                .eq(TUser::getPassword,password);
        TUser user=tUserService.getOne(tUserWrapper);
        if (user!=null){
            session.setAttribute("loginEmail",email);
            return "redirect:/blog/index";
        }else {
            return "redirect:/toLogin";
        }

    }
}

